using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace qPrintComponent
{
    //typedef struct _PRINTER_INFO_5 { 
    //  LPTSTR    pPrinterName;                 :0
    //  LPTSTR    pPortName;                    :1
    //  DWORD     Attributes;                   :2
    //  DWORD     DeviceNotSelectedTimeout;     :3
    //  DWORD     TransmissionRetryTimeout;     :4
    //} PRINTER_INFO_5, *PPRINTER_INFO_5;    

    public sealed class PrinterInfo5 : qSafePrinterInfo
    {
        internal PrinterInfo5(SafeHandle PrinterHandle)
            : base(PrinterHandle,5)
        { }

        public override string ToString()
        {
            return PortName;
        }
        [Description("The name of the printer (local or remote).")]
        [NotifyParentProperty(true)]
        public string PrinterName
        {
            get { return GetStringField(0);}
            set 
            {
                if (value != this.PrinterName)
                {
                    bool b = false;
                    foreach (string name in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                    {
                        if (name == value)
                            b = true;
                    }
                    if (!b) SetStringField(0, value);
                }
            }
        }
        [Description(@"The port(s) used to transmit data to the printer. If a printer is connected to more than one port, the names of each port must be separated by commas (for example, 'LPT1:,LPT2:,LPT3:').")]
        public string PortName
        {
            get { return GetStringField(1);}
        }
        [Description("The printer attributes.")]
        public qAttributes Attributes
        {
            get { return new qAttributes(this, GetIntField(2));}
        }
        [Description("The maximum time, in milliseconds, allowed to elapse between attempts to select a device.")]
        public int DeviceNotSelectedTimeout
        {
            get { return GetIntField(3); }
        }
        [Description("The maximum time, in milliseconds, allowed to elapse between transmission retries.")]
        public int TransmissionRetryTimeout
        {
            get { return GetIntField(4); }
        }
    }
}
